package br.com.cefetrn.apoena.converter;

import java.util.Map;

import br.com.cefetrn.apoena.dominio.entity.Profissional;

public class Converter4Profissional extends AxConverterAPOENA {

	/**
	 * @see com.opensymphony.webwork.util.WebWorkTypeConverter#convertFromString(java.util.Map, java.lang.String[], java.lang.Class)
	 */
	@SuppressWarnings("unchecked")
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
		try {
			
			if (arg1 == null || arg1[0]==null) 
				return null;
			
			return getSession(arg0).load(Profissional.class, arg1[0]);
			
		} catch (Exception e) {
			
			LOG.error(arg1[0], e);
			
			return null;
		}
	}

	/**
	 * @see com.opensymphony.webwork.util.WebWorkTypeConverter#convertToString(java.util.Map, java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	public String convertToString(Map arg0, Object arg1) {
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
		try {
			
			LOG.debug(arg1);
			
			return toString((Profissional)arg1);
			
		} catch (Exception e) {
			
			LOG.error(arg1, e);
			
			return "erro";
		}
	}
		
	public String toString(Profissional profissional) {
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
		String str = "";
		
		try {
			
			str = profissional.getCadastro();
			
		} catch (Exception e) {
			LOG.error(profissional, e);
		}
		return str; 
	}

}
